﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace com.lib.manager
{
    
   
    /// <summary>
    /// 线程guanliqi9
    /// </summary>
    public class IThreadManager
    {

        /// <summary>
        /// 单例
        /// </summary>
        private static IThreadManager instance = null;


        public static IThreadManager Instance
        {

            get
            {
                if (instance == null)
                {
                    instance = new IThreadManager();
                }

                return instance;
            }
        }


        /// <summary>
        /// 获取线程
        /// </summary>
        public bool getThread(System.Action<object> o,params object[] data)
        {
            if (o == null)
            {
                Logger.Log("Your Method Is Can't be Empty,Please Check!");
                return false;
            }

            Hashtable hash = new Hashtable();
            hash["obj"] = o;
            hash["data"] = data;
            return ThreadPool.QueueUserWorkItem(DoThread, hash);
        }


        /// <summary>
        /// 线程处理,返回消息
        /// </summary>
        /// <param name="o"></param>
        private void DoThread(object o)
        {
            Hashtable hash = o as Hashtable;
            System.Action<object> call = hash["obj"] as System.Action<object>;
            object[] data = hash["data"] as object[];
            call(data);
        }


    }
}
